home *** CD-ROM | disk | FTP | other *** search
/ Champak 62 / Volume 62 - JOGO DISK .iso / Games / penguin_dinner.swf / scripts / __Packages / classes / game / GameBoard.as < prev    next >
Text File  |  2008-03-17  |  16KB  |  385 lines

  1. class classes.game.GameBoard extends classes.ui.AbstractWidget
  2. {
  3.    var pickupMoneyMessageTimeoutID = null;
  4.    function GameBoard()
  5.    {
  6.       super();
  7.       this.widgetMan = classes.core.WidgetManager.getInstance();
  8.       this.soundMan = classes.core.SoundManager.getInstance();
  9.       this.soundMan.startMusicTrack("game_track");
  10.       this.doLater(this.init);
  11.    }
  12.    function init()
  13.    {
  14.       classes.core.SOManager.getInstance().__set__dayScore(0);
  15.       this.tv_clip.gotoAndStop("tv_" + String(classes.core.SOManager.getInstance().__get__upgradeTV()));
  16.       var _loc10_ = classes.core.SOManager.getInstance().__get__currentStage();
  17.       this.background_mc.gotoAndStop("stage_" + _loc10_);
  18.       this.pause_btn.addEventListener(classes.ui.IconicButton.CLICK,this,"onButtonClick");
  19.       this.company_btn.addEventListener(classes.ui.IconicButton.CLICK,this,"onButtonClick");
  20.       this.trashcan_btn.addEventListener(classes.ui.IconicButton.CLICK,this,"onButtonClick");
  21.       var _loc5_ = [new classes.math.Tile(11,1),new classes.math.Tile(23,1),new classes.math.Tile(17,5),new classes.math.Tile(11,10),new classes.math.Tile(23,10)];
  22.       var _loc8_ = [new classes.math.Tile(11,1),new classes.math.Tile(23,1),new classes.math.Tile(17,2),new classes.math.Tile(11,7),new classes.math.Tile(23,7)];
  23.       var _loc7_ = [new classes.math.Tile(8,1),new classes.math.Tile(20,1),new classes.math.Tile(14,5),new classes.math.Tile(8,10),new classes.math.Tile(20,10)];
  24.       var _loc6_ = [new classes.math.Tile(14,1),new classes.math.Tile(26,1),new classes.math.Tile(20,5),new classes.math.Tile(14,10),new classes.math.Tile(26,10)];
  25.       var _loc9_ = [[8,8],[8,8],[8,8],[10,8],[8,10]];
  26.       this.allOrderPlates = [];
  27.       this.allTables = [];
  28.       var _loc2_ = 0;
  29.       while(_loc2_ < 5)
  30.       {
  31.          var _loc4_ = this["order_plate_btn_" + _loc2_];
  32.          _loc4_.index = _loc2_;
  33.          _loc4_.addEventListener(classes.ui.IconicButton.CLICK,this,"onButtonClick");
  34.          this.allOrderPlates.push(_loc4_);
  35.          var _loc3_ = this.objects_mc["table_" + _loc2_];
  36.          this["table_" + _loc2_] = _loc3_;
  37.          this.allTables.push(_loc3_);
  38.          _loc3_.tileUpCoords = _loc8_[_loc2_];
  39.          _loc3_.tileDownCoords = _loc5_[_loc2_];
  40.          _loc3_.tileLeftPlace = _loc7_[_loc2_];
  41.          _loc3_.tileRightPlace = _loc6_[_loc2_];
  42.          _loc3_.guestsSpeeds = _loc9_[_loc2_];
  43.          _loc3_.addEventListener(classes.ui.IconicButton.CLICK,this,"onButtonClick");
  44.          _loc2_ = _loc2_ + 1;
  45.       }
  46.       this.goal_tf.text = String(classes.game.GameData.__get__DAY_GOAL());
  47.       this.score_tf.text = String(0);
  48.       this.lastCommand = null;
  49.       this.hero = this.objects_mc.hero;
  50.       this.heroQueue = new classes.game.HeroCommandQueue();
  51.       this.guestsQueue = [];
  52.       classes.game.Guest.selectedGuests = [];
  53.       this.nextGuestAppearCounter = Math.floor(classes.game.GameData.__get__GUEST_APPEAR_TIME() * 0.5);
  54.       this.attachedClipCount = 0;
  55.       this.foodCooking = [];
  56.       this.showClosedSign = true;
  57.       this.totalGuestsOnScreen = 0;
  58.       this.timer = new classes.utils.Timer(classes.game.GameData.DAY_TIME);
  59.       this.gamePaused = false;
  60.       this.startLocalLoop(this.update);
  61.    }
  62.    function onButtonClick(e)
  63.    {
  64.       switch(e.target)
  65.       {
  66.          case this.table_0:
  67.          case this.table_1:
  68.          case this.table_2:
  69.          case this.table_3:
  70.          case this.table_4:
  71.             var _loc3_ = this.hero._y < e.target._y ? e.target.tileUpCoords : e.target.tileDownCoords;
  72.             this.heroQueue.enqueue(new classes.game.Command(classes.game.Command.TYPE_MOVE_TO_TABLE,e.target,{tileX:_loc3_.x,tileY:_loc3_.y}));
  73.             break;
  74.          case this.order_plate_btn_0:
  75.          case this.order_plate_btn_1:
  76.          case this.order_plate_btn_2:
  77.          case this.order_plate_btn_3:
  78.          case this.order_plate_btn_4:
  79.             this.heroQueue.enqueue(new classes.game.Command(classes.game.Command.TYPE_MOVE_TO_ORDER_PLATE,e.target,{tileX:15 - 3 * e.target.index,tileY:11}));
  80.             break;
  81.          case this.trashcan_btn:
  82.             this.heroQueue.enqueue(new classes.game.Command(classes.game.Command.TYPE_MOVE_TO_TRASHCAN,this.trashcan_btn));
  83.             break;
  84.          case this.pause_btn:
  85.             this.widgetMan.lockAllGlobal();
  86.             this.lastCommand = new classes.game.Command(classes.game.Command.TYPE_PAUSE_GAME);
  87.             break;
  88.          case this.company_btn:
  89.             classes.utils.URLCaller.mainLink();
  90.       }
  91.    }
  92.    function unpauseGame()
  93.    {
  94.       for(var _loc3_ in this.objects_mc)
  95.       {
  96.          var _loc2_ = this.objects_mc[_loc3_];
  97.          if(_loc2_.__proto__ == classes.game.Guest.prototype)
  98.          {
  99.             _loc2_.unpause();
  100.          }
  101.       }
  102.       classes.core.WidgetManager.getInstance().unlockAllGlobal();
  103.       this.timer.unpause();
  104.       this.gamePaused = false;
  105.    }
  106.    function update()
  107.    {
  108.       if(this.gamePaused)
  109.       {
  110.          return undefined;
  111.       }
  112.       if(this.lastCommand.type == classes.game.Command.TYPE_PAUSE_GAME)
  113.       {
  114.          this.gamePaused = true;
  115.          this.lastCommand = null;
  116.          this.heroQueue.clear();
  117.          for(var _loc10_ in this.objects_mc)
  118.          {
  119.             var _loc7_ = this.objects_mc[_loc10_];
  120.             if(_loc7_.__proto__ == classes.game.Guest.prototype)
  121.             {
  122.                _loc7_.pause();
  123.             }
  124.          }
  125.          this.pauseMenu = classes.core.WidgetManager.getInstance().createWidget(classes.core.WidgetManager.WIDGET_PAUSE_MENU,this,this.getNextHighestDepth());
  126.          this.pauseMenu.addEventListener(classes.ui.AbstractWidget.DISPOSE,this,"unpauseGame");
  127.          return undefined;
  128.       }
  129.       this.timer.update();
  130.       var _loc17_ = Math.floor((1 - this.timer.__get__percentLeft()) * 1000);
  131.       this.background_mc.clock.gotoAndStop(_loc17_);
  132.       this.background_mc.atmospheric.gotoAndStop(_loc17_);
  133.       if(this.timer.__get__percentLeft() == 0)
  134.       {
  135.          if(this.showClosedSign)
  136.          {
  137.             this.showClosedSign = false;
  138.             this.objects_mc.attachMovie("closed_sign","closed_sign",this.objects_mc.getNextHighestDepth(),{_x:50,_y:210});
  139.          }
  140.          if(this.totalGuestsOnScreen == 0)
  141.          {
  142.             var _loc16_ = 0;
  143.             for(_loc10_ in this.allTables)
  144.             {
  145.                var _loc14_ = this.allTables[_loc10_];
  146.                _loc16_ += _loc14_.earnings;
  147.             }
  148.             if(_loc16_ == 0)
  149.             {
  150.                this.stopLocalLoop();
  151.                classes.core.Application.getInstance().gotoDayResultScreen();
  152.                return undefined;
  153.             }
  154.             if(this.pickupMoneyMessageTimeoutID == null)
  155.             {
  156.                this.pickupMoneyMessageTimeoutID = _global.setTimeout(this,"showPickupMoneyMessage",4000);
  157.             }
  158.          }
  159.       }
  160.       this.lastCommand = this.heroQueue.dequeue();
  161.       if(this.lastCommand != null)
  162.       {
  163.          switch(this.lastCommand.type)
  164.          {
  165.             case classes.game.Command.TYPE_MOVE_TO_TRASHCAN:
  166.                this.hero.targetObj = this.lastCommand.target;
  167.                this.hero.moveTo(21,11);
  168.                break;
  169.             case classes.game.Command.TYPE_MOVE_TO_ORDER_PLATE:
  170.                this.hero.targetObj = this.lastCommand.target;
  171.                this.hero.moveTo(this.lastCommand.data.tileX,this.lastCommand.data.tileY);
  172.                break;
  173.             case classes.game.Command.TYPE_MOVE_TO_TABLE:
  174.                _loc14_ = this.lastCommand.target;
  175.                var _loc11_ = classes.game.Guest.selectedGuests;
  176.                if(_loc11_.length > 0 && _loc14_.isFree())
  177.                {
  178.                   _loc10_ = 0;
  179.                   while(_loc10_ < _loc11_.length)
  180.                   {
  181.                      _loc11_[1].speed = _loc14_.guestsSpeeds[_loc10_];
  182.                      _loc11_[_loc10_].moveToTable(_loc14_);
  183.                      _loc10_ = _loc10_ + 1;
  184.                   }
  185.                   this.onGuestLeaveQueue();
  186.                   this.heroQueue.open();
  187.                }
  188.                else
  189.                {
  190.                   this.hero.targetObj = this.lastCommand.target;
  191.                   this.hero.moveTo(this.lastCommand.data.tileX,this.lastCommand.data.tileY);
  192.                }
  193.          }
  194.       }
  195.       this.nextGuestAppearCounter = this.nextGuestAppearCounter + 1;
  196.       if(this.nextGuestAppearCounter >= classes.game.GameData.__get__GUEST_APPEAR_TIME() && this.timer.__get__percentLeft() > 0)
  197.       {
  198.          if(this.guestsQueue.length < 3 && this.totalGuestsOnScreen < classes.game.GameData.__get__MAX_GUESTS_AT_ONCE())
  199.          {
  200.             this.addNewGuest();
  201.          }
  202.          this.nextGuestAppearCounter = 0;
  203.       }
  204.       for(_loc10_ in this.objects_mc)
  205.       {
  206.          _loc7_ = this.objects_mc[_loc10_];
  207.          _loc7_.update();
  208.          var _loc9_ = Math.floor((_loc7_._y - 140) / 20) * 100 + Math.floor((_loc7_._x + 20) / 20);
  209.          if(!_loc7_.atTable)
  210.          {
  211.             _loc9_ += 50;
  212.          }
  213.          if(_loc7_.getDepth() != _loc9_)
  214.          {
  215.             _loc7_.swapDepths(_loc9_);
  216.          }
  217.       }
  218.       if(this.hero.targetObjReached)
  219.       {
  220.          switch(this.hero.targetObj)
  221.          {
  222.             case this.table_0:
  223.             case this.table_1:
  224.             case this.table_2:
  225.             case this.table_3:
  226.             case this.table_4:
  227.                _loc14_ = this.hero.targetObj;
  228.                var _loc12_ = _loc14_.guests;
  229.                if(_loc12_.length == 0 && _loc14_.earnings > 0)
  230.                {
  231.                   this.soundMan.startSound("money_pickup");
  232.                   classes.core.SOManager.getInstance().dayScore = classes.core.SOManager.getInstance().dayScore + _loc14_.earnings;
  233.                   this.score_tf.text = String(classes.core.SOManager.getInstance().__get__dayScore());
  234.                   _loc14_.takeMoney();
  235.                }
  236.                else
  237.                {
  238.                   _loc10_ = 0;
  239.                   while(_loc10_ < _loc12_.length)
  240.                   {
  241.                      var _loc6_ = _loc12_[_loc10_];
  242.                      switch(_loc6_.state)
  243.                      {
  244.                         case classes.game.Guest.STATE_WAITING_FOR_WAITER:
  245.                            _loc6_.makeOrder();
  246.                            this.foodCooking.push({type:_loc6_.food,time:0});
  247.                            break;
  248.                         case classes.game.Guest.STATE_WAITING_FOR_FOOD:
  249.                            if(this.hero.giveFood(_loc6_.food))
  250.                            {
  251.                               this.soundMan.startSound("food_give");
  252.                               _loc6_.startEating();
  253.                               _loc14_.showFood(_loc6_);
  254.                            }
  255.                      }
  256.                      _loc10_ = _loc10_ + 1;
  257.                   }
  258.                }
  259.                break;
  260.             case this.order_plate_btn_0:
  261.             case this.order_plate_btn_1:
  262.             case this.order_plate_btn_2:
  263.             case this.order_plate_btn_3:
  264.             case this.order_plate_btn_4:
  265.                var _loc5_ = this.hero.targetObj;
  266.                if(this.hero.takeReadyFood(_loc5_.foodType))
  267.                {
  268.                   this.soundMan.startSound("food_pickup");
  269.                   _loc5_.setType(classes.game.Food.TYPE_NONE);
  270.                }
  271.                break;
  272.             case this.trashcan_btn:
  273.                this.hero.clearFood();
  274.          }
  275.          this.heroQueue.open();
  276.       }
  277.       var _loc4_ = 0;
  278.       while(_loc4_ < this.foodCooking.length)
  279.       {
  280.          var _loc8_ = this.foodCooking[_loc4_];
  281.          _loc8_.time = _loc8_.time + 1;
  282.          if(_loc8_.time >= classes.game.GameData.__get__FOOD_COOKING_TIME())
  283.          {
  284.             var _loc3_ = 0;
  285.             while(_loc3_ < 5)
  286.             {
  287.                _loc5_ = this["order_plate_btn_" + _loc3_];
  288.                if(_loc5_.foodType == classes.game.Food.TYPE_NONE)
  289.                {
  290.                   this.soundMan.startSound("food_ready");
  291.                   _loc5_.setType(_loc8_.type);
  292.                   this.foodCooking.splice(_loc4_,1);
  293.                   _loc4_ = _loc4_ - 1;
  294.                   break;
  295.                }
  296.                _loc3_ = _loc3_ + 1;
  297.             }
  298.          }
  299.          _loc4_ = _loc4_ + 1;
  300.       }
  301.       this.lastCommand = null;
  302.    }
  303.    function showPickupMoneyMessage()
  304.    {
  305.       this.attachMovie("pickup_money_warning","pickup_money_warning",this.getNextHighestDepth());
  306.       this.soundMan.startSound("message_popup");
  307.    }
  308.    function addNewGuest()
  309.    {
  310.       var _loc3_ = this.guestsQueue.length;
  311.       if(Math.random() <= classes.game.GameData.__get__GUEST_DOUBLE_APPEAR_PROBABILITY())
  312.       {
  313.          this.objects_mc.attachMovie("guest","guest_" + this.attachedClipCount,this.attachedClipCount);
  314.          var _loc2_ = this.objects_mc["guest_" + this.attachedClipCount];
  315.          this.attachedClipCount = this.attachedClipCount + 1;
  316.          this.objects_mc.attachMovie("guest","guest_" + this.attachedClipCount,this.attachedClipCount);
  317.          var _loc5_ = this.objects_mc["guest_" + this.attachedClipCount];
  318.          this.attachedClipCount = this.attachedClipCount + 1;
  319.          _loc2_.speed = 9;
  320.          _loc5_.speed = 8;
  321.          var _loc6_ = [[new classes.math.Tile(7,2),new classes.math.Tile(6,4)],[new classes.math.Tile(5,2),new classes.math.Tile(4,4)],[new classes.math.Tile(3,2),new classes.math.Tile(2,4)]];
  322.          _loc2_.setup(_loc5_,new classes.math.Tile(0,2),_loc6_[_loc3_][0],_loc3_ == 0);
  323.          _loc5_.setup(_loc2_,new classes.math.Tile(0,4),_loc6_[_loc3_][1],_loc3_ == 0);
  324.          _loc2_.addEventListener(classes.game.Guest.EVENT_LEAVE_QUEUE,this,"onGuestLeaveQueue");
  325.          _loc2_.addEventListener(classes.game.Guest.EVENT_LEAVE_SCREEN,this,"onGuestLeaveScreen");
  326.          this.guestsQueue.push([_loc2_,_loc5_]);
  327.       }
  328.       else
  329.       {
  330.          this.objects_mc.attachMovie("guest","guest_" + this.attachedClipCount,this.attachedClipCount);
  331.          var _loc4_ = this.objects_mc["guest_" + this.attachedClipCount];
  332.          this.attachedClipCount = this.attachedClipCount + 1;
  333.          _loc4_.speed = 8;
  334.          var _loc7_ = [new classes.math.Tile(6,3),new classes.math.Tile(4,3),new classes.math.Tile(2,3)];
  335.          _loc4_.setup(null,new classes.math.Tile(0,3),_loc7_[_loc3_],_loc3_ == 0);
  336.          _loc4_.addEventListener(classes.game.Guest.EVENT_LEAVE_QUEUE,this,"onGuestLeaveQueue");
  337.          _loc4_.addEventListener(classes.game.Guest.EVENT_LEAVE_SCREEN,this,"onGuestLeaveScreen");
  338.          this.guestsQueue.push([_loc4_]);
  339.       }
  340.       this.totalGuestsOnScreen = this.totalGuestsOnScreen + 1;
  341.    }
  342.    function onGuestLeaveScreen(e)
  343.    {
  344.       this.totalGuestsOnScreen = this.totalGuestsOnScreen - 1;
  345.    }
  346.    function onGuestLeaveQueue(e)
  347.    {
  348.       this.guestsQueue.shift();
  349.       var _loc2_ = 0;
  350.       while(_loc2_ < this.guestsQueue.length)
  351.       {
  352.          var _loc3_ = 0;
  353.          while(_loc3_ < this.guestsQueue[_loc2_].length)
  354.          {
  355.             var _loc4_ = this.guestsQueue[_loc2_][_loc3_];
  356.             _loc4_.shiftInQueue(_loc2_ == 0);
  357.             _loc3_ = _loc3_ + 1;
  358.          }
  359.          _loc2_ = _loc2_ + 1;
  360.       }
  361.       classes.game.Guest.selectedGuests = [];
  362.    }
  363.    function dispose()
  364.    {
  365.       this.pause_btn.dispose();
  366.       this.company_btn.dispose();
  367.       this.trashcan_btn.dispose();
  368.       if(this.pauseMenu)
  369.       {
  370.          this.pauseMenu.dispose();
  371.       }
  372.       for(var _loc5_ in this.allOrderPlates)
  373.       {
  374.          var _loc3_ = this.allOrderPlates[_loc5_];
  375.          _loc3_.dispose();
  376.       }
  377.       for(_loc5_ in this.allTables)
  378.       {
  379.          var _loc4_ = this.allTables[_loc5_];
  380.          _loc4_.dispose();
  381.       }
  382.       super.dispose();
  383.    }
  384. }
  385.